package com.lengxf.mybatis.config;

import com.zaxxer.hikari.HikariDataSource;

import java.util.Properties;

public class UserHikariConfig {

    public static HikariDataSource build() {
        HikariDataSource hikariDataSource = new HikariDataSource();
        hikariDataSource.setAutoCommit(true);
        hikariDataSource.setMaxLifetime(3600000);
        hikariDataSource.setMinimumIdle(8);
        hikariDataSource.setConnectionTimeout(30000);
        hikariDataSource.setConnectionTestQuery("SELECT 1");
        hikariDataSource.setIdleTimeout(600000);
        hikariDataSource.setMaximumPoolSize(64);
        hikariDataSource.setDataSourceProperties(properties());
        return hikariDataSource;
    }

    private static Properties properties() {
        Properties properties = new Properties();
        properties.setProperty("cachePrepStmts", "true");
        properties.setProperty("prepStmtCacheSize", "250");
        properties.setProperty("prepStmtCacheSqlLimit", "2048");
        properties.setProperty("useServerPrepStmts", "true");
        return properties;
    }

}
